﻿/***************************************************************
 * Name:      HouseholdManagementMain.cpp
 * Purpose:   Code for Application Frame
 * Author:    JHC (wqvbjhc@gmail.com)
 * Created:   2012-08-30
 * Copyright: JHC (http://my.csdn.net/wqvbjhc)
 * License:
 **************************************************************/

#include "HouseholdManagementMain.h"
#include "HouseholdManagementApp.h"
#include "PublicData.h"
#include <wx/msgdlg.h>

//(*InternalHeaders(HouseholdManagementFrame)
#include <wx/artprov.h>
#include <wx/bitmap.h>
#include <wx/icon.h>
#include <wx/intl.h>
#include <wx/image.h>
#include <wx/string.h>
//*)
#include "TransparentStaticText.h"
#include "sqlite3.h"
#include "DlgType.h"
#include "DlgUser.h"
#include "DlgMenu.h"
#include "DlgMeals.h"
#include "DlgCash.h"
#include "DlgRent.h"
#include "DlgDailyNecess.h"
#include "DlgReportCash.h"
#include "DlgReportMeals.h"
#include "DlgReportMenu.h"
#include "DlgReportDay.h"
#include "DlgReportMonth.h"
#include "DlgReportYear.h"
#include "DlgReportDailyNecess.h"
#include "DlgReportRent.h"
//helper functions
enum wxbuildinfoformat {
    short_f, long_f
};

const long HouseholdManagementFrame::IDMenuQuit= wxNewId();
const long HouseholdManagementFrame::IDMenuAbout= wxNewId();
const long HouseholdManagementFrame::ID_STATUSBAR1= wxNewId();
const long HouseholdManagementFrame::ID_M_BACKUP= wxNewId();
const long HouseholdManagementFrame::ID_M_RESTORE= wxNewId();
const long HouseholdManagementFrame::ID_M_OPT= wxNewId();
const long HouseholdManagementFrame::ID_M_TYPE= wxNewId();
const long HouseholdManagementFrame::ID_M_USER= wxNewId();
const long HouseholdManagementFrame::ID_M_MENU= wxNewId();
const long HouseholdManagementFrame::ID_M_MEALS= wxNewId();
const long HouseholdManagementFrame::ID_M_CASH= wxNewId();
const long HouseholdManagementFrame::ID_M_RENT= wxNewId();
const long HouseholdManagementFrame::ID_M_OIL= wxNewId();
const long HouseholdManagementFrame::ID_M_GAS= wxNewId();
const long HouseholdManagementFrame::ID_M_RICE= wxNewId();
const long HouseholdManagementFrame::ID_M_REPORT_CASH= wxNewId();
const long HouseholdManagementFrame::ID_M_REPORT_MEALS= wxNewId();
const long HouseholdManagementFrame::ID_M_REPORT_MENU= wxNewId();
const long HouseholdManagementFrame::ID_M_REPORT_DAY= wxNewId();
const long HouseholdManagementFrame::ID_M_REPORT_MONTH= wxNewId();
const long HouseholdManagementFrame::ID_M_REPORT_YEAR= wxNewId();
const long HouseholdManagementFrame::ID_M_REPORT_DAILYNECESS= wxNewId();
const long HouseholdManagementFrame::ID_M_REPORT_RENT= wxNewId();

const long HouseholdManagementFrame::ID_BTN_MEALS= wxNewId();
const long HouseholdManagementFrame::ID_BTN_RICE= wxNewId();
const long HouseholdManagementFrame::ID_BTN_OIL= wxNewId();
const long HouseholdManagementFrame::ID_BTN_GAS= wxNewId();
const long HouseholdManagementFrame::ID_BTN_RENT= wxNewId();
const long HouseholdManagementFrame::ID_BTN_RCASH= wxNewId();
const long HouseholdManagementFrame::ID_BTN_RMEALS= wxNewId();
const long HouseholdManagementFrame::ID_BTN_RMENU= wxNewId();
const long HouseholdManagementFrame::ID_BTN_RDAY= wxNewId();
const long HouseholdManagementFrame::ID_BTN_RMONTH= wxNewId();
const long HouseholdManagementFrame::ID_BTN_RYEAR= wxNewId();
const long HouseholdManagementFrame::ID_BTN_RDAILYNECESS= wxNewId();
const long HouseholdManagementFrame::ID_BTN_RRENT= wxNewId();
const long HouseholdManagementFrame::ID_BTN_LIVINGEXP= wxNewId();

wxString wxbuildinfo(wxbuildinfoformat format)
{
//    wxString wxbuild(wxVERSION_STRING);
//
//    if (format == long_f ) {
//#if defined(__WXMSW__)
//        wxbuild << _T("-Windows");
//#elif defined(__UNIX__)
//        wxbuild << _T("-Linux");
//#endif
//
//#if wxUSE_UNICODE
//        wxbuild << _T("-Unicode build");
//#else
//        wxbuild << _T("-ANSI build");
//#endif // wxUSE_UNICODE
//    }
    wxString wxbuild=_T("献给老婆大人的小作\r\n\r\n作者:陈吉宏\r\n\r\nEmail:wqvbjhc@gmail.com");
    return wxbuild;
}


BEGIN_EVENT_TABLE(HouseholdManagementFrame,wxFrame)
    EVT_ERASE_BACKGROUND(HouseholdManagementFrame::OnEraseBackground)
END_EVENT_TABLE()

HouseholdManagementFrame::HouseholdManagementFrame(wxWindow* parent,wxWindowID id)
{
    Create(parent, id, _T("家庭管理小软件"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE, _T("id"));
    SetClientSize(wxSize(923,527));
    {
        wxIcon FrameIcon;
        FrameIcon.CopyFromBitmap(wxArtProvider::GetBitmap(wxART_MAKE_ART_ID_FROM_STR(_T("wxART_HARDDISK")),wxART_BUTTON));
        SetIcon(FrameIcon);
    }
    CenterOnScreen();
    InitMenu();
}
void HouseholdManagementFrame::InitMenu()
{
    wxMenuBar* m_Menu;

    m_Menu = new wxMenuBar();
    m_MFile = new wxMenu();
    m_MBackup = new wxMenuItem(m_MFile, ID_M_BACKUP, _T("备份数据库"), wxEmptyString, wxITEM_NORMAL);
    m_MFile->Append(m_MBackup);
    m_MRestore = new wxMenuItem(m_MFile, ID_M_RESTORE, _T("还原数据库"), wxEmptyString, wxITEM_NORMAL);
    m_MFile->Append(m_MRestore);
    m_MOptimize = new wxMenuItem(m_MFile, ID_M_OPT, _T("优化数据库"), wxEmptyString, wxITEM_NORMAL);
    m_MFile->Append(m_MOptimize);
    m_MQuit = new wxMenuItem(m_MFile, IDMenuQuit, _T("退出\tAlt-F4"), _T("Quit the application"), wxITEM_NORMAL);
    m_MFile->Append(m_MQuit);
    m_Menu->Append(m_MFile, _T("文件"));

    m_MData = new wxMenu();
    m_MType = new wxMenuItem(m_MData, ID_M_TYPE, _T("类别管理"), wxEmptyString, wxITEM_NORMAL);
    m_MData->Append(m_MType);
    m_MUser = new wxMenuItem(m_MData, ID_M_USER, _T("用户管理"), wxEmptyString, wxITEM_NORMAL);
    m_MData->Append(m_MUser);
    m_MMenu = new wxMenuItem(m_MData, ID_M_MENU, _T("菜谱管理"), wxEmptyString, wxITEM_NORMAL);
    m_MData->Append(m_MMenu);
    m_Menu->Append(m_MData, _T("基础数据"));

    m_MDaily = new wxMenu();
    m_MMeals = new wxMenuItem(m_MDaily, ID_M_MEALS, _T("伙食"), wxEmptyString, wxITEM_NORMAL);
    m_MDaily->Append(m_MMeals);
    m_MCash = new wxMenuItem(m_MDaily, ID_M_CASH, _T("现金管理"), wxEmptyString, wxITEM_NORMAL);
    m_MDaily->Append(m_MCash);
    m_MRent = new wxMenuItem(m_MDaily, ID_M_RENT, _T("房租管理"), wxEmptyString, wxITEM_NORMAL);
    m_MDaily->Append(m_MRent);
    m_MOil = new wxMenuItem(m_MDaily, ID_M_OIL, _T("用油管理"), wxEmptyString, wxITEM_NORMAL);
    m_MDaily->Append(m_MOil);
    m_MGas = new wxMenuItem(m_MDaily, ID_M_GAS, _T("用气管理"), wxEmptyString, wxITEM_NORMAL);
    m_MDaily->Append(m_MGas);
    m_MRice = new wxMenuItem(m_MDaily, ID_M_RICE, _T("用米管理"), wxEmptyString, wxITEM_NORMAL);
    m_MDaily->Append(m_MRice);
    m_Menu->Append(m_MDaily, _T("日常生活"));

    m_MReport = new wxMenu();
    m_MR_Cash = new wxMenuItem(m_MReport, ID_M_REPORT_CASH, _T("现金流查询"), wxEmptyString, wxITEM_NORMAL);
    m_MReport->Append(m_MR_Cash);
    m_MR_Meals = new wxMenuItem(m_MReport, ID_M_REPORT_MEALS, _T("用餐信息查询"), wxEmptyString, wxITEM_NORMAL);
    m_MReport->Append(m_MR_Meals);
    m_MR_Menu = new wxMenuItem(m_MReport, ID_M_REPORT_MENU, _T("用菜信息查询"), wxEmptyString, wxITEM_NORMAL);
    m_MReport->Append(m_MR_Menu);
    m_MR_Day = new wxMenuItem(m_MReport, ID_M_REPORT_DAY, _T("日生活报表"), wxEmptyString, wxITEM_NORMAL);
    m_MReport->Append(m_MR_Day);
    m_MR_Month = new wxMenuItem(m_MReport, ID_M_REPORT_MONTH, _T("月生活报表"), wxEmptyString, wxITEM_NORMAL);
    m_MReport->Append(m_MR_Month);
    m_MR_Year = new wxMenuItem(m_MReport, ID_M_REPORT_YEAR, _T("年生活报表"), wxEmptyString, wxITEM_NORMAL);
    m_MReport->Append(m_MR_Year);
    m_MR_DailyNecess = new wxMenuItem(m_MReport, ID_M_REPORT_DAILYNECESS, _T("柴米油盐报表"), wxEmptyString, wxITEM_NORMAL);
    m_MReport->Append(m_MR_DailyNecess);
    m_MR_Rent = new wxMenuItem(m_MReport, ID_M_REPORT_RENT, _T("柴米油盐报表"), wxEmptyString, wxITEM_NORMAL);
    m_MReport->Append(m_MR_Rent);
    m_Menu->Append(m_MReport, _T("报表查询"));

    m_MHelp = new wxMenu();
    m_MAbout = new wxMenuItem(m_MHelp, IDMenuAbout, _T("关于\tF1"), _T("Show info about this application"), wxITEM_NORMAL);
    m_MHelp->Append(m_MAbout);
    m_Menu->Append(m_MHelp, _T("帮助"));

    SetMenuBar(m_Menu);
    m_StatusBar = new wxStatusBar(this, ID_STATUSBAR1, 0, _T("ID_STATUSBAR1"));
    int __wxStatusBarWidths_1[1] = { -1 };
    int __wxStatusBarStyles_1[1] = { wxSB_NORMAL };
    m_StatusBar->SetFieldsCount(1,__wxStatusBarWidths_1);
    m_StatusBar->SetStatusStyles(1,__wxStatusBarStyles_1);
    SetStatusBar(m_StatusBar);

//按钮布局

    wxBoxSizer *topSizerH_=new wxBoxSizer(wxHORIZONTAL);
    wxBoxSizer *topSizerV_=new wxBoxSizer(wxVERTICAL);
    wxBoxSizer *conSizer=new wxBoxSizer(wxVERTICAL);//顶层窗口布局,从上到下包含每个了窗口布局

    wxBoxSizer *firSize=new wxBoxSizer(wxHORIZONTAL);
    wxBoxSizer *secSize=new wxBoxSizer(wxHORIZONTAL);
    wxBoxSizer *thiSize=new wxBoxSizer(wxHORIZONTAL);

    btn_meals_=new wxButton(this,ID_BTN_MEALS,_T("伙食"));
    btn_rice_=new wxButton(this,ID_BTN_RICE,_T("米"));
    btn_oil_=new wxButton(this,ID_BTN_OIL,_T("油"));
    btn_gas_=new wxButton(this,ID_BTN_GAS,_T("煤气"));
    btn_rent_=new wxButton(this,ID_BTN_RENT,_T("房租"));
    btn_livingexp_=new wxButton(this,ID_BTN_LIVINGEXP,_T("月生活费"));
    btn_rcash_=new wxButton(this,ID_BTN_RCASH,_T("现金流"));
    btn_rmeals_=new wxButton(this,ID_BTN_RMEALS,_T("用餐信息"));
    btn_rmenu_=new wxButton(this,ID_BTN_RMENU,_T("用菜信息"));
    btn_rday_=new wxButton(this,ID_BTN_RDAY,_T("日生活报表"));
    btn_rmonth_=new wxButton(this,ID_BTN_RMONTH,_T("月生活报表"));
    btn_ryear_=new wxButton(this,ID_BTN_RYEAR,_T("年生活报表"));
    btn_rdailynecess_=new wxButton(this,ID_BTN_RDAILYNECESS,_T("柴米油盐报表"));
    btn_rrent_=new wxButton(this,ID_BTN_RRENT,_T("房租报表"));

    wxStaticText *stat_text=new wxStaticText(this,wxID_ANY,_T("支出"),wxDefaultPosition, wxDefaultSize, wxTRANSPARENT_WINDOW);
    //stat_text->SetBackgroundStyle(wxBG_STYLE_TRANSPARENT);
    firSize->Add(stat_text,1, wxFIXED_MINSIZE|wxALL|wxALIGN_CENTER,5);
    firSize->Add(btn_meals_,1, wxFIXED_MINSIZE|wxALL|wxALIGN_CENTER,5);
    firSize->Add(btn_rice_,1, wxFIXED_MINSIZE|wxALL|wxALIGN_CENTER,5);
    firSize->Add(btn_oil_,1, wxFIXED_MINSIZE|wxALL|wxALIGN_CENTER,5);
    firSize->Add(btn_gas_,1, wxFIXED_MINSIZE|wxALL|wxALIGN_CENTER,5);
    firSize->Add(btn_rent_,1, wxFIXED_MINSIZE|wxALL|wxALIGN_CENTER,5);
    secSize->Add(new wxStaticText(this,wxID_ANY,_T("收入"), wxDefaultPosition, wxDefaultSize, wxTRANSPARENT_WINDOW),1, wxFIXED_MINSIZE|wxALL|wxALIGN_CENTER,5);
    secSize->Add(btn_livingexp_,1, wxFIXED_MINSIZE|wxALL|wxALIGN_CENTER,5);
    thiSize->Add(new wxStaticText(this,wxID_ANY,_T("报表")),1, wxFIXED_MINSIZE|wxALL|wxALIGN_CENTER,5);
    thiSize->Add(btn_rcash_,1, wxFIXED_MINSIZE|wxALL|wxALIGN_CENTER,5);
    thiSize->Add(btn_rmeals_,1, wxFIXED_MINSIZE|wxALL|wxALIGN_CENTER,5);
    thiSize->Add(btn_rmenu_,1, wxFIXED_MINSIZE|wxALL|wxALIGN_CENTER,5);
    thiSize->Add(btn_rday_,1, wxFIXED_MINSIZE|wxALL|wxALIGN_CENTER,5);
    thiSize->Add(btn_rmonth_,1, wxFIXED_MINSIZE|wxALL|wxALIGN_CENTER,5);
    thiSize->Add(btn_ryear_,1, wxFIXED_MINSIZE|wxALL|wxALIGN_CENTER,5);
    thiSize->Add(btn_rdailynecess_,1, wxFIXED_MINSIZE|wxALL|wxALIGN_CENTER,5);
    thiSize->Add(btn_rrent_,1, wxFIXED_MINSIZE|wxALL|wxALIGN_CENTER,5);

    conSizer->Add(firSize,0,wxFIXED_MINSIZE|wxALL|wxALIGN_LEFT,0);
    conSizer->Add(secSize,0,wxFIXED_MINSIZE|wxALL|wxALIGN_LEFT,0);
    conSizer->Add(thiSize,0,wxFIXED_MINSIZE|wxALL|wxALIGN_LEFT,0);
    topSizerH_->Add(conSizer,1,wxFIXED_MINSIZE|wxALL|wxALIGN_CENTER,0);
    topSizerV_->Add(topSizerH_,1,wxFIXED_MINSIZE|wxALL|wxALIGN_CENTER,0);
    SetSizer(topSizerV_);//绑定对话框和布局控件
    SetAutoLayout(true);
    topSizerV_->SetSizeHints(this);//设置对话框最小大小

//控件事件
    Connect(IDMenuQuit,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&HouseholdManagementFrame::OnQuit);
    Connect(IDMenuAbout,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&HouseholdManagementFrame::OnAbout);
    Connect(ID_M_BACKUP,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&HouseholdManagementFrame::OnMBackup);
    Connect(ID_M_RESTORE,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&HouseholdManagementFrame::OnMRestore);
    Connect(ID_M_OPT,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&HouseholdManagementFrame::OnMOpt);
    Connect(ID_M_TYPE,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&HouseholdManagementFrame::OnMType);
    Connect(ID_M_USER,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&HouseholdManagementFrame::OnMUser);
    Connect(ID_M_MENU,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&HouseholdManagementFrame::OnMMenu);
    Connect(ID_M_MEALS,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&HouseholdManagementFrame::OnMMeals);
    Connect(ID_M_CASH,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&HouseholdManagementFrame::OnMCash);
    Connect(ID_M_RENT,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&HouseholdManagementFrame::OnMRent);
    Connect(ID_M_OIL,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&HouseholdManagementFrame::OnMOil);
    Connect(ID_M_GAS,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&HouseholdManagementFrame::OnMGas);
    Connect(ID_M_RICE,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&HouseholdManagementFrame::OnMRice);
    Connect(ID_M_REPORT_CASH,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&HouseholdManagementFrame::OnMReportCash);
    Connect(ID_M_REPORT_MEALS,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&HouseholdManagementFrame::OnMReportMeals);
    Connect(ID_M_REPORT_MENU,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&HouseholdManagementFrame::OnMReportMenu);
    Connect(ID_M_REPORT_DAY,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&HouseholdManagementFrame::OnMReportDay);
    Connect(ID_M_REPORT_MONTH,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&HouseholdManagementFrame::OnMReportMonth);
    Connect(ID_M_REPORT_YEAR,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&HouseholdManagementFrame::OnMReportYear);
    Connect(ID_M_REPORT_DAILYNECESS,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&HouseholdManagementFrame::OnMReportDailyNecess);
    Connect(ID_M_REPORT_RENT,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&HouseholdManagementFrame::OnMReportRent);

    Connect(ID_BTN_MEALS,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&HouseholdManagementFrame::OnMMeals);
    Connect(ID_BTN_RICE,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&HouseholdManagementFrame::OnMRice);
    Connect(ID_BTN_OIL,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&HouseholdManagementFrame::OnMOil);
    Connect(ID_BTN_GAS,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&HouseholdManagementFrame::OnMGas);
    Connect(ID_BTN_RENT,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&HouseholdManagementFrame::OnMRent);
    Connect(ID_BTN_RCASH,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&HouseholdManagementFrame::OnMReportCash);
    Connect(ID_BTN_RMEALS,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&HouseholdManagementFrame::OnMReportMeals);
    Connect(ID_BTN_RMENU,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&HouseholdManagementFrame::OnMReportMenu);
    Connect(ID_BTN_RDAY,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&HouseholdManagementFrame::OnMReportDay);
    Connect(ID_BTN_RMONTH,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&HouseholdManagementFrame::OnMReportMonth);
    Connect(ID_BTN_RYEAR,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&HouseholdManagementFrame::OnMReportYear);
    Connect(ID_BTN_RDAILYNECESS,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&HouseholdManagementFrame::OnMReportDailyNecess);
    Connect(ID_BTN_RRENT,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&HouseholdManagementFrame::OnMReportRent);
    Connect(ID_BTN_LIVINGEXP,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&HouseholdManagementFrame::OnMCash);
}

HouseholdManagementFrame::~HouseholdManagementFrame()
{
    //(*Destroy(HouseholdManagementFrame)
    //*)
}
void HouseholdManagementFrame::OnEraseBackground(wxEraseEvent& event)
{
    if(wxFileName::FileExists(app_conf_.bgPicPath)==false) {
        event.Skip();
        return;
    }
    if(wxImage::CanRead(app_conf_.bgPicPath)==false) {
        event.Skip();
        return;
    }
    wxImage image;
    wxBitmap m_background;
    if (image.LoadFile(app_conf_.bgPicPath, wxBITMAP_TYPE_ANY)) {
        m_background = wxBitmap(image);
    } else {
        event.Skip();
        return;
    }
    if (m_background.Ok()) {
        wxSize sz = GetClientSize();
        if (event.GetDC()) {
            // Create a memory DC
            wxMemoryDC temp_dc;
            temp_dc.SelectObject(m_background);
            event.GetDC()->StretchBlit(0, 0, sz.x, sz.y, &temp_dc, 0, 0,m_background.GetWidth(),m_background.GetHeight());
        } else {
            wxClientDC dc(this);
            wxMemoryDC temp_dc;
            temp_dc.SelectObject(m_background);
            dc.StretchBlit(0, 0, sz.x, sz.y, &temp_dc, 0, 0,m_background.GetWidth(),m_background.GetHeight());
        }
    } else {
        event.Skip();    // The official way of doing it
    }
}

void HouseholdManagementFrame::OnQuit(wxCommandEvent& event)
{
    Close();
}

void HouseholdManagementFrame::OnAbout(wxCommandEvent& event)
{
    wxString msg = wxbuildinfo(long_f);
    wxMessageBox(msg, _T("关于..."));
}
void HouseholdManagementFrame::OnMBackup(wxCommandEvent& event)
{
    wxBusyCursor wait;
    wxString caption = wxT("备份数据库");
    wxString wildcard = _T("备份文件(*.HouseholdMan)|*.HouseholdMan|All Files (*.*)|*.*||");
    wxString defaultDir=wxT(".");
    wxString defaultFileName = wxT("");
    wxFileDialog dialog(this,caption,defaultDir,defaultFileName,wildcard,wxFD_SAVE);
    if( dialog.ShowModal() == wxID_OK) {
        wxString FilePath_Name = dialog.GetPath();
        if(SQLITE_OK!=loadOrSaveDb(g_db,FilePath_Name.mb_str(wxConvUTF8),true)) {
            wxMessageBox(wxString::Format(_T("%s%s"),sqlite3_errmsg(g_db),_T("备份出错，请重启后再试。")),_T("备份出错"),wxOK);
        } else {
            wxMessageBox(_T("备份完成。备份路径为[")+FilePath_Name+_T("]"),_T("备份成功"),wxOK);
        }
    }
    wxLogDebug(_T("OnMBackup"));
}

void HouseholdManagementFrame::OnMRestore(wxCommandEvent& event)
{
    wxBusyCursor wait;
    wxString caption = wxT("还原数据库");
    wxString wildcard = _T("备份文件(*.HouseholdMan)|*.HouseholdMan|All Files (*.*)|*.*||");
    wxString defaultDir=wxT(".");
    wxString defaultFileName = wxT("");
    wxFileDialog dialog(this,caption,defaultDir,defaultFileName,wildcard,wxFD_OPEN);
    if( dialog.ShowModal() == wxID_OK) {
        wxString FilePath_Name = dialog.GetPath();
        wxString tip=_T("还原后无法撤消，确定还原？");
        if(wxNO==wxMessageBox(tip,_T("确认还原操作"),wxYES_NO)) {
            return;
        }
        tip=wxTheApp->GetAppName()+_T("_systembackup");
        loadOrSaveDb(g_db,tip,true);
        if(SQLITE_OK!=loadOrSaveDb(g_db,FilePath_Name.mb_str(wxConvUTF8),false)) {
            wxMessageBox(wxString::Format(_T("%s%s"),sqlite3_errmsg(g_db),_T("还原过程出错，原数据库可能被破坏。")),_T("还原出错"),wxOK);
        } else {
            wxMessageBox(_T("还原成功。"),_T("还原成功"),wxOK);
        }
    }
    wxLogDebug(_T("OnMRestore"));
}
void HouseholdManagementFrame::OnMOpt(wxCommandEvent& event)
{
    wxString tip=_T("优化数据库存储，压缩文件尺寸，是否继续？\r\n");
    wxString strAppPath ;
    wxStandardPathsBase& stdp = wxStandardPaths::Get();
    wxFileName exeFile(stdp.GetExecutablePath());
    strAppPath = exeFile.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR);
    wxString filepath;
    filepath.Printf(wxT("%s%c%s"),strAppPath,wxFILE_SEP_PATH,g_DBFILENAME);
    tip+=filepath+_T("\r\n");
    tip+=_T("提示：优化操作过程中出现任何故障，数据库都必须从备份文件中恢复数据。请在操作前对数据库进行备份");
    if(wxNO==wxMessageBox(tip,_T("确认还原操作"),wxYES_NO)) {
        return;
    }
    sqlite3_exec(g_db, "VACUUM;", 0, 0,NULL);
}
void HouseholdManagementFrame::OnMType(wxCommandEvent& event)
{
    CDlgType dlg(this);
    dlg.CenterOnParent();
    dlg.ShowModal();
}
void HouseholdManagementFrame::OnMUser(wxCommandEvent& event)
{
    CDlgUser dlg(NULL);
    dlg.CenterOnParent();
    dlg.ShowModal();
}

void HouseholdManagementFrame::OnMMenu(wxCommandEvent& event)
{
    CDlgMenu dlg(NULL);
    dlg.CenterOnParent();
    dlg.ShowModal();
}

void HouseholdManagementFrame::OnMMeals(wxCommandEvent& event)
{
    CDlgMeals dlg(NULL);
    dlg.CenterOnParent();
    dlg.ShowModal();
}

void HouseholdManagementFrame::OnMCash(wxCommandEvent& event)
{
    CDlgCash dlg(NULL);
    dlg.CenterOnParent();
    dlg.ShowModal();
}

void HouseholdManagementFrame::OnMReportCash(wxCommandEvent& event)
{
    CDlgReportCash dlg(NULL);
    dlg.CenterOnParent();
    dlg.ShowModal();
}

void HouseholdManagementFrame::OnMReportMeals(wxCommandEvent& event)
{
    CDlgReportMeals dlg(NULL);
    dlg.CenterOnParent();
    dlg.ShowModal();
}

void HouseholdManagementFrame::OnMReportMenu(wxCommandEvent& event)
{
    CDlgReportMenu dlg(NULL);
    dlg.CenterOnParent();
    dlg.ShowModal();
}

void HouseholdManagementFrame::OnMReportDay(wxCommandEvent& event)
{
    CDlgReportDay dlg(NULL);
    dlg.CenterOnParent();
    dlg.ShowModal();
}

void HouseholdManagementFrame::OnMReportMonth(wxCommandEvent& event)
{
    CDlgReportMonth dlg(NULL);
    dlg.CenterOnParent();
    dlg.ShowModal();
}

void HouseholdManagementFrame::OnMReportYear(wxCommandEvent& event)
{
    CDlgReportYear dlg(NULL);
    dlg.CenterOnParent();
    dlg.ShowModal();
}

void HouseholdManagementFrame::OnMReportDailyNecess(wxCommandEvent& event)
{
    CDlgReportDailyNecess dlg(NULL);
    dlg.CenterOnParent();
    dlg.ShowModal();
}

void HouseholdManagementFrame::OnMReportRent(wxCommandEvent& event)
{
    CDlgReportRent dlg(NULL);
    dlg.CenterOnParent();
    dlg.ShowModal();
}

void HouseholdManagementFrame::OnMRent(wxCommandEvent& event)
{
    CDlgRent dlg(NULL);
    dlg.CenterOnParent();
    dlg.ShowModal();
}

void HouseholdManagementFrame::OnMOil(wxCommandEvent& event)
{
    CDlgDailyNecess dlg(_T("18"),NULL);
    dlg.CenterOnParent();
    dlg.ShowModal();
}

void HouseholdManagementFrame::OnMGas(wxCommandEvent& event)
{
    CDlgDailyNecess dlg(_T("100"),NULL);
    dlg.CenterOnParent();
    dlg.ShowModal();
}

void HouseholdManagementFrame::OnMRice(wxCommandEvent& event)
{
    CDlgDailyNecess dlg(_T("19"),NULL);
    dlg.CenterOnParent();
    dlg.ShowModal();
}
